#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :quadratic.py
# @Time      :2021/3/1 14:05
# @Author    :Letquit
"""
文件说明：请定义一个函数quadratic(a, b, c)，接收3个参数，返回一元二次方程 ax^2+bx+c=0的两个解。

"""
import math


def quadratic(a, b, c):
    if isinstance(a, (int, float)) and isinstance(b, (int, float)) and isinstance(c, (int, float)):
        delta = b ** 2 - 4 * a * c
        if delta >= 0:
            x1 = (-b + math.sqrt(delta)) / (2 * a)
            x2 = (-b - math.sqrt(delta)) / (2 * a)
            return x1, x2
        else:
            return '该方程无解'
    else:
        raise TypeError('bad operand type')




# 测试:
print('quadratic(2, 3, 1) =', quadratic(2, 3, 1))
print('quadratic(1, 3, -4) =', quadratic(1, 3, -4))
print('quadratic(1, 1, -4) =', quadratic(1, 1, 1))
print('quadratic(A, 3, -4) =', quadratic('A', 3, -4))

if quadratic(2, 3, 1) != (-0.5, -1.0):
    print('测试失败')
elif quadratic(1, 3, -4) != (1.0, -4.0):
    print('测试失败')
else:
    print('测试成功')
if __name__ == "__main__":
    run_code = 0
